<!--
 * @Description: 报表数据
-->
<template>
  <div class="statement-data">
    <div class="relation-data-title">
      <div class="font-600"
        >{{ data.subject }}
        <a-tooltip placement="leftTop">
          <template slot="title"> <div v-html="helpText"></div> </template
          > <icon-font type="cap-icon-weibiaoti6-copy" class="icon-font" />  </a-tooltip
      ></div>
      <span
        v-if="data.showMore"
        class="title-more"
        :href="moreUrl"
        @click="open"
        target="_blank"
        style="font-weight: 500;">{{ $i18n('common.more.label') }}</span
      >
    </div>
    <template v-if="list && list.data && list.data.length">
      <table-comp v-if="isShowTable" :data="data" :list="list"></table-comp>
      <chart-list :chartList="chartList" :key="index" :data="data" :list="list"></chart-list>
    </template>
  </div>
</template>
<script>
  /*global openCtpWindow*/
  import { useTemplateStore } from '@/store/modules/template';
  import { mapWritableState } from 'pinia';
  import globalData from '@/plugins/data';
  import mixins from '../mixins';
  import TableComp from './table.vue'
  import ChartList from './chart-list.vue'

  export default {
    name: 'StatementData',
    mixins: [mixins],
    components: {
      TableComp,
      ChartList
    },
    computed: {
      ...mapWritableState(useTemplateStore, ['zwIframe', 'isIframeReady']),
      //问号移上去的帮助性文案
      helpText() {
        return `${$.i18n('common.datarelation.note')}`;
      },
      moreUrl() {
        const { id: affairId } = this.baseInfo.businessData.affair;
        const { capType, formQueryId, id } = this.data;
        let url = ''
        if (capType === "4") {
          url = `${globalData.ctxPath}/report4Result.do?method=showResult&designId=${formQueryId}&type=drQuery&hidelocation=false&affairId=${affairId}&drPoId=${id}&queryId=${formQueryId}`
        } else {
          url = `${globalData.ctxPath}/report/queryReport.do?method=index&_resourceCode=F08_reportviewindex`
          if (this.data?.formQueryId) {
            let zwIframe = window._getZWIframe()
            const formDataId = zwIframe.contentAPI.getContentDataId()
            url = `${globalData.ctxPath}/report/queryReport.do?method=goIndexRight&masterId=${formDataId}&type=drQuery&affairId=${affairId}&drPoId=${id}&reportId=${formQueryId}`
          }
        }
        return url
      },
      // 是否显示表格
      isShowTable() {
        const res = this.data?.showTable === 1
        return res
      },
      // 图表
      chartList() {
        return this.data?.chartItemList || []
      }
    },
    methods: {
      open() {
        openCtpWindow({
          url: this.moreUrl,
          id: 'templateSend'
        });
      }
    }
  };
</script>
<style lang="scss" scoped>
  .form-table-data {
    margin: 10px 0;
  }
  ::v-deep .form-table-data {
    td, tr {
      white-space: nowrap;
    }
    th, td {
      vertical-align: middle;
      height: 38px;
    }
  }
</style>
